/*
 * --------------------------------------------------------------
 * Copyright ©  2015 Hangzhou DtDream Technologies Co.,Ltd.
 * --------------------------------------------------------------
 *      Product: 协同数治
 *  Module Name: jimu
 * Date Created: 2022/11/17
 *  Description: 测试接口
 * --------------------------------------------------------------
 * Modification History
 * DATE            NAME            Description
 * --------------------------------------------------------------
 * 2022/11/17       yewj            测试接口
 * --------------------------------------------------------------
 */

package com.dtdream.jimu.controller;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.dtdream.jimu.entity.User;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试接口
 *
 * @Author: yewj
 **/
@RestController
@RequestMapping("/test")
public class TestController {

    /**
     * 测试post请求的接口
     * @author: yewj
     * @param user
     * @return JSON
     * @throws
     * @date 2022/11/17
     */
    @PostMapping(value = "/testMethodOne")
    public JSON testMethodOne(@RequestBody User user) {
        String eventMessage = "[{\"name\":\"小明\", \"age\":12}, {\"name\":\"小明\", \"age\":12}, {\"name\":\"小明\", " +
                "\"age\":12}, {"+ "\"name\":" + "\"" + user.getName() + "\"" + ", \"age\":" + user.getAge() + "}]";
        JSONArray array = JSONUtil.parseArray(eventMessage);
        JSONObject entries = new JSONObject();
        entries.set("data", array);
        return entries;
    }

    /**
     * 测试get请求的接口
     * @author: yewj
     * @param name
     * @return JSON
     * @throws
     * @date 2022/11/17
     */
    @GetMapping(value = "/testMethodTwo")
    public JSON testMethodTwo(String name) {
        String eventMessage = "[{\"name\":\"小明\", \"age\":12}, {\"name\":\"小明\", \"age\":12}, {\"name\":\"小明\", " +
                "\"age\":12}, {"+ "\"name\":" + "\"" + name + "\"" + ", \"age\":" + 0 + "}]";
        JSONArray array = JSONUtil.parseArray(eventMessage);
        JSONObject entries = new JSONObject();
        entries.set("data", array);
        return entries;
    }

}
